package com.interauto.service.kaklis;

import com.interauto.AppliCation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

/**
 * 往消息队列里扔要运行的任务信息
 */
@Component
public class RunTaskProducer {
    private static final Logger logger= LoggerFactory.getLogger(RunTaskProducer.class);
    private static final String runtasktopic="autoruntaskinfo"; //处理定时任务的topic
    private static final String autoalarmtopic="autoalarmtopic";  //处理告警的topic
    @Autowired
    private KafkaTemplate<String,Object> kafkaTemplate;

    public void addtaskinfo(String taskinfo){
        logger.info(String.format("send task info is-->%s",taskinfo));
        try{
            kafkaTemplate.send(runtasktopic,taskinfo);
        }
        catch (Exception e){
            logger.error("send taskinf is system error;"+e);
            e.printStackTrace();
        }
    }

    public void addautoalarm(String alarminfo){
        logger.info(String.format("send alarminfo info is-->%s",alarminfo));
        try{
            kafkaTemplate.send(autoalarmtopic,alarminfo);
        }
        catch (Exception e){
            logger.error("send alarminfo is system error;"+e);
            e.printStackTrace();
        }
    }


    public static void main(String[] args) {
        ConfigurableApplicationContext ctx=new SpringApplicationBuilder(AppliCation.class).run(args);
        RunTaskProducer appliCation=ctx.getBean("runTaskProducer",RunTaskProducer.class);
        appliCation.addautoalarm("aabbbccdd");
    }
}
